package com.wms.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wms.context.BaseContext;
import com.wms.dto.UserBackPageQueryDTO;
import com.wms.entity.WmsType;
import com.wms.entity.WmsUserback;
import com.wms.exception.TypeDeleteException;
import com.wms.mapper.UserBackMapper;
import com.wms.mapper.UserMapper;
import com.wms.result.PageResult;
import com.wms.service.UserBackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class UserBackServiceImpl implements UserBackService {
    @Autowired
    private UserBackMapper userBackMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public void delete(List<Integer> ids) {
        userBackMapper.delete(ids);
    }

    @Override
    public PageResult page(UserBackPageQueryDTO userBackPageQueryDTO) {
        log.info("分页查询仓库信息:{}", userBackPageQueryDTO);
        PageHelper.startPage(userBackPageQueryDTO.getPage(), userBackPageQueryDTO.getPageSize());
        Page<WmsUserback> page = userBackMapper.pageQuery(userBackPageQueryDTO);
        long total = page.getTotal();
        List<WmsUserback> result = page.getResult();
        return new PageResult(total, result);
    }

    @Override
    public void save(WmsUserback wmsUserBack) {
        //设置当前用户
        wmsUserBack.setUserName(userMapper.getById(BaseContext.getCurrentId()));
        //设置提交时间
        wmsUserBack.setCreatedTime(LocalDateTime.now());
        userBackMapper.save(wmsUserBack);
    }
}
